package com.gua.encrypt.dto;

import static org.springframework.http.HttpStatus.BAD_REQUEST;
import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR;
import static org.springframework.http.HttpStatus.NOT_FOUND;
import static org.springframework.http.HttpStatus.OK;

import org.springframework.http.ResponseEntity;

import com.gua.common.response.AjaxResult;

/**
 * @author huangjj
 * @description 返回值构造
 */
public interface AjaxResultBuilder {

	/**
	 * 成功的构造
	 * 
	 * @param data 数据
	 * @return Result
	 */
	default ResponseEntity<AjaxResult<?>> success(Object data) {
		return ResponseEntity.ok(AjaxResult.builder()
				.code(OK.value())
				.data(data)
				.build());
	}

	/**
	 * 400的构造
	 * 
	 * @param errorMsg 错误信息
	 * @return Result
	 */
	default ResponseEntity<AjaxResult<?>> badRequest(String errorMsg) {
		return ResponseEntity.badRequest()
				.body(AjaxResult.builder()
						.code(BAD_REQUEST.value())
						.msg(errorMsg).build());
	}

	/**
	 * 404的构造
	 * 
	 * @param errorMsg 错误信息
	 * @return Result
	 */
	default ResponseEntity<AjaxResult<?>> notFound(String errorMsg) {
		return ResponseEntity.status(NOT_FOUND.value())
				.body(AjaxResult.builder()
						.code(NOT_FOUND.value())
						.msg(errorMsg)
						.build());
	}

	/**
	 * 500的构造
	 * 
	 * @param errorMsg 错误信息
	 * @return Result
	 */
	default ResponseEntity<AjaxResult<?>> internalServerError(String errorMsg) {
		return ResponseEntity.status(INTERNAL_SERVER_ERROR.value())
				.body(AjaxResult.builder()
						.code(INTERNAL_SERVER_ERROR.value())
						.msg(errorMsg)
						.build());
	}

}